package main

func findBall(grid [][]int) []int {
	result := make([]int, len(grid[0]))
outer:
	for i := range grid[0] {
		x := i
		for j := range grid { // 纵坐标
			if grid[j][x] == 1 {
				if x == len(grid[0])-1 || grid[j][x+1] == -1 {
					// 到最右边了或v形，卡住
					result[i] = -1
					continue outer
				} else {
					// 向右滚动到下一排,
					x++
				}
			} else {
				// grid[j][x] == -1
				if x == 0 || grid[j][x-1] == 1 {
					result[i] = -1
					continue outer
				} else {
					x--
				}
			}
		}
		result[i] = x
	}
	return result
}

func main() {
	grid := [][]int{
		{1, 1, 1, 1, 1, 1},
		{-1, -1, -1, -1, -1, -1},
		{1, 1, 1, 1, 1, 1},
		{-1, -1, -1, -1, -1, -1},
	}
	res := findBall(grid)
	println(res)
}
